﻿using System;
using System.Html;
using Quicklight.Web.Html;
using jQueryApi;

namespace Quicklight.Web.Razor {

   /// <summary>
   /// Does the binding on behalf of a declarative binding of a ObservableList to the inner content of an element
   /// For example <div>@Binding(ViewModel.Items)</div>
   /// </summary>
   /// <typeparam name="T">Type of items in the ObservableList</typeparam>
   public class ObservableListContentBinder<T> : ContentBinder {
      private ObservableList<T> list;

      /// <summary>
      /// Constructs a ObservableListContentBinder for binding the ObservableList to the inner content of an element
      /// </summary>
      /// <param name="list">ObservableList to bind to the inner content of an element</param>
      public ObservableListContentBinder(ObservableList<T> list) {
         this.list = list;
      }

      /// <summary>
      /// Bind method does the actual binding of the ObservableList to the inner content of the specified element
      /// </summary>
      /// <param name="element">Element with which the binding must occur</param>
      protected override void Bind(Element element) {
         element.Bind<T>(list);

         jQueryObject jQueryObject = jQuery.FromElement(element);
         jQueryObject.Text(list.ToString());
      }
   }
}
